﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using SysRoutesMobile.ServiceReference1;

namespace SysRoutesMobile
{
    public partial class BuscarLinha : PhoneApplicationPage
    {
        static ServiceReference1.Service1SoapClient ws = new ServiceReference1.Service1SoapClient();

        public BuscarLinha()
        {
            InitializeComponent();
            LoaderListPicker();
            ws.ListarParadasCompleted += Select;
            //ws.ParadaIDSelectCompleted += SelectParadaID;
            ws.BuscarLinhaCompleted += BuscadorLinha;
        }

        
        public void LoaderListPicker()
        {
            ws.ListarParadasAsync();
        }
         

        public void Select(object sender, ServiceReference1.ListarParadasCompletedEventArgs e)
        {
            List<SysRoutesMobile.ServiceReference1.Parada> list = e.Result.ToList();
            foreach (SysRoutesMobile.ServiceReference1.Parada p in list)
            {
                listPicker1.Items.Add(p);
                listPicker2.Items.Add(p);
            }
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            int id0 = (listPicker1.SelectedItem as Parada).id_parada;
            int id1 = (listPicker2.SelectedItem as Parada).id_parada;
            ws.BuscarLinhaAsync(id0, id1);
            // ws.ParadaIDSelectAsync(listPicker1.SelectedItem.ToString(), listPicker2.SelectedItem.ToString());
        }

        /*
        public void SelectParadaID(object sender, ServiceReference1.ParadaIDSelectCompletedEventArgs e)
        {
            SysRoutesMobile.ServiceReference1.ArrayOfInt id_paradas = e.Result;
            ws.BuscarLinhaAsync(id_paradas[0], id_paradas[1]);
        }*/

        public void BuscadorLinha(object sender, ServiceReference1.BuscarLinhaCompletedEventArgs e)
        {
            List<SysRoutesMobile.ServiceReference1.Linha> list = e.Result.ToList();
            String s1 = "Linhas1: ";

            foreach (SysRoutesMobile.ServiceReference1.Linha l in list)
            {
                s1 += l.numero + " ";
            }

            MessageBox.Show(s1);
        }
    }
}